home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / archiver / zoo21src.zoo / zoolist.c < prev    next >
C/C++ Source or Header  |  1991-07-24  |  20KB  |  594 lines

  1. #ifndef LINT
  2. /* derived from: zoolist.c 2.27 88/08/15 11:03:16 */
  3. static char sccsid[]="$Source: g:/newzoo\RCS\zoolist.c,v $\n\
  4. $Id: zoolist.c,v 1.4 1991/07/24 23:58:04 bjsjr Rel $";
  5. #endif /* LINT */
  6.  
  7. /*
  8. If TRACE_LIST is defined, any list command may be followed
  9. by 'D' to show verbose information about each directory
  10. entry in the archive.   Do not define both TRACE_LIST and
  11. TRACE_IO else a symbol conflict will occur and in any case
  12. duplicate information will be dumped.
  13. */
  14.  
  15. /* #define TRACE_LIST */
  16.  
  17. /*
  18. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  19. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  20. */
  21. #include "options.h"
  22. #include "portable.h"
  23. #include "zoomem.h"  /* to get ZOOCOUNT */
  24.  
  25. /* Lists files in archive */
  26. #include "zoo.h"
  27. #include "errors.i"
  28. #include "zooio.h"
  29. #include "various.h"
  30. #include "zoofns.h"
  31.  
  32. #ifdef TRACE_LIST
  33. void show_dir PARMS ((struct direntry *direntry));
  34. static int trace_list = 0;
  35. #endif /* TRACE_LIST */
  36.  
  37. static char tot_fmt[] = "%8lu %3u%% %8lu  %4d file";
  38. static char tot_line[] =
  39.    /* "------------  --------  ---  --------  --------- --------\n"; */
  40.    "--------  --- --------  --------- --------\n";
  41.  
  42. static char dbl_percent[] = "Archive %s:  %s";
  43.  
  44. extern int quiet;                /* assumed initialized to zero */
  45.  
  46. void show_comment PARMS((struct direntry *, ZOOFILE, int, char *));
  47. int ver_too_high PARMS((struct zoo_header *));
  48. int needed PARMS((char *, struct direntry *, struct zoo_header *));
  49. void printtz PARMS((int));
  50.  
  51. void zoolist (argv, option, argc)
  52. char **argv, *option;
  53. int argc;
  54. {
  55. char whichname[PATHSIZE];  /* which name to use */
  56. char *this_zoo;            /* currently matched archive name */
  57. register ZOOFILE zoo_file;
  58. char *flist[ZOOCOUNT];       /* list of ptrs to input archive names */
  59. int fptr;                  /* will point to within list of archive names */
  60.  
  61. struct direntry direntry;
  62. struct zoo_header zoo_header;
  63. int size_factor;
  64. unsigned long tot_org_siz = 0L, tot_siz_now = 0L;
  65. int   tot_sf;
  66. int file_count = 0;
  67. int del_count = 0;                  /* number of deleted entries */
  68. int bad_pack;                 /* 1 if packing method is unknown */
  69. static char *month_list="000JanFebMarAprMayJunJulAugSepOctNovDec";
  70. static char dashes[] = "------------\n";
  71. int year, month, day, hours, min, sec;
  72. int list_deleted = 0;         /* list deleted files too */
  73. int fast = 0;                 /* fast list */
  74. long fiz_ofs = 0;             /* offset where to start */
  75. long dat_ofs = 0;             /* ... data offset of file data */
  76. int verb_list = 0;            /* if verbose listing needed */
  77. int show_name = 0;            /* if archive name to be included in listing */
  78. int show_crc = 0;                    /* if crc should be listed */
  79. int zoocount = 1;             /* number of archives to list */
  80. int biglist = 0;              /* multiarchive listing */
  81. int one_col = 0;                    /* one column listing requested */
  82. int showdir = 0;                    /* show directory name in fast listing */
  83. int longest;                  /* length of longest archive name */
  84. int talking;                        /* opposite of quiet */
  85. int column = 0;               /* for column printing */
  86. int first_ever = 1;                /* first time ever -- very special case */
  87. int neednl = 0;                    /* whether to print a newline */
  88. int need_acmt = 0;                /* show archive comment */
  89. int show_gen = 0;                    /* show generation count */
  90. int genson = 1;                    /* enable/disable generations */
  91. #ifdef FATTR
  92. int show_mode = 0;                /* show file protection */
  93. #endif
  94. int first_dir = 1;                /* if first direntry -- to adjust dat_ofs */
  95.  
  96. while (*option) {
  97.    switch (*option) {
  98.       case 'a': show_name++; break;
  99. #ifdef TRACE_LIST
  100.         case 'D': trace_list++; break;
  101. #endif /* TRACE_LIST */
  102.       case 'd': list_deleted++; break;
  103.       case 'f': fast++; break;
  104.         case 'g': show_gen++; break;
  105.         case '/': showdir++; break;
  106.         case 'A':
  107.         case 'v': need_acmt++; break;
  108.       case 'V': need_acmt++; /* fall through */
  109.       case 'c': verb_list++; break;
  110.         case 'C': show_crc++; break;
  111.       case 'l': break;
  112.       case 'L': biglist++; zoocount = argc; break;
  113. #ifdef FATTR
  114.         case 'm': show_mode++; break;
  115. #endif
  116.         case '1': one_col++; break;
  117.         case '+': genson = 1; break;
  118.         case '-': genson = 0; break;
  119.         /* following code same as in zooext.c */
  120.       case '@':     /* if @m,n specified, fiz_ofs = m, dat_ofs = n */
  121.             {
  122.                 char *comma_pos;
  123.                 ++option;
  124.                 comma_pos = strchr(option, ',');
  125.                 if (comma_pos != NULL) {
  126.                     dat_ofs = calc_ofs (comma_pos + 1);
  127.                     *comma_pos = '\0';
  128.                 }
  129.                 fiz_ofs = calc_ofs(option); 
  130.                 goto no_more;
  131.             }
  132.         case 'q': quiet++; break;
  133.       default:
  134.          prterror ('w', option_ignored, *option);
  135.    }
  136.    option++;
  137. }
  138.  
  139. no_more:  /* come from exit from while loop above */
  140.  
  141. if (fast && show_name) {      /* don't allow 'a' with 'f' */
  142.    show_name = 0;
  143.    prterror ('w', option_ignored, 'a');
  144. }
  145.  
  146. talking = !quiet;                    /* for convenience */
  147.  
  148. #ifdef WILDCARD
  149.    /* For each archive name supplied, if it is not a char range and
  150.       does not contain a dot, append "*.zoo". */
  151.    {
  152.       int i;
  153.       for (i = 0; i < argc;  i++) {
  154.          if (strchr (nameptr (argv[i]), EXT_CH) == NULL && 
  155.                            !match_half (nameptr (argv[0]), "?-?"))
  156.             argv[i] = newcat (argv[i], "*.zoo");
  157.       }
  158.    }
  159. #endif
  160.  
  161. makelist (zoocount, argv, flist,        ZOOCOUNT-2,   (char *) NULL,".","..", &longest);
  162. /*        ^argc     ^argv ^list_pointer ^max_no_files   ^exclude */
  163.  
  164. for (fptr = 0;  (this_zoo = flist[fptr]) != NULL; fptr++) {
  165.    int ercount;                  /* count of errors */
  166.    int entrycount;               /* count of directory entries */
  167.    int expl_deleted;             /* explain what D means */
  168.    int expl_comment;             /* explain what comment means */
  169.    int expl_ver;                 /* Explain what V means */
  170.    int expl_star;                /* Explain what * means */
  171.    int first_time;               /* first time through loop for an archive */
  172.  
  173.    ercount = entrycount = del_count =
  174.       expl_deleted = expl_comment = expl_ver = expl_star = 0;
  175.  
  176.     if (talking)
  177.         column = 0;                        /* if quiet, names will run together */
  178.  
  179.    first_time = 1;
  180.  
  181. #ifndef WILDCARD
  182.    /* Add default extension if none supplied */
  183.    if (strchr (nameptr (this_zoo), EXT_CH) == NULL)
  184.       this_zoo = newcat (this_zoo, EXT_DFLT);
  185. #endif
  186.  
  187.    zoo_file = zooopen (this_zoo, Z_READ);
  188.  
  189.    if (zoo_file == NOFILE) {
  190.       prterror ('e', could_not_open, this_zoo);
  191.       continue;
  192.    } else if (!show_name && talking)
  193.       printf ("\nArchive %s:\n", this_zoo);
  194.    
  195. if (fiz_ofs != 0L) {                /* if offset specified, start there */
  196.     prterror ('m', start_ofs, fiz_ofs, dat_ofs);
  197.    zooseek (zoo_file, fiz_ofs, 0);
  198. } else {
  199.    if (frd_zooh (&zoo_header, zoo_file) == -1 ||
  200.                                              zoo_header.zoo_tag != ZOO_TAG) {
  201.       prterror ('e', dbl_percent, this_zoo, invalid_header);
  202.       goto loop_end;
  203.    }
  204. #if 0
  205.     if (talking && (!show_name || verb_list || need_acmt))
  206. #else
  207.     if (need_acmt && talking)
  208. #endif
  209.     {
  210.         void show_acmt PARMS ((struct zoo_header *, ZOOFILE, int));
  211.         show_acmt (&zoo_header, zoo_file, 0);        /* show archive comment */
  212.     }
  213.  
  214.    /* Seek to the beginning of the first directory entry */
  215.    if (zooseek (zoo_file, zoo_header.zoo_start, 0) != 0) {
  216.       ercount++;
  217.       prterror ('e', dbl_percent, this_zoo, bad_directory);
  218.       goto loop_end;
  219.    }
  220.    if (!show_name && ver_too_high (&zoo_header)) {
  221.       ercount++;
  222.       if (ercount < 2)
  223.          prterror ('M', wrong_version, 
  224.                                         zoo_header.major_ver, zoo_header.minor_ver);
  225.    }
  226. } /* end if (fiz_ofs !- 0L) */
  227.  
  228.    /* Now we print information about each file in the archive */
  229.    
  230.    if (!show_name) { /* initialize for each file only if not disk catalog */
  231.       tot_org_siz = 0L;  
  232.       tot_siz_now = 0L;
  233.       file_count = 0;
  234.       del_count = 0;
  235.    }
  236.  
  237.    while (1) {
  238. #ifndef GLOB
  239.       if (readdir (&direntry, zoo_file, 0) == -1) {
  240. #else
  241.       if (zreaddir (&direntry, zoo_file, 0) == -1) {
  242. #endif /* GLOB */
  243.